package com.hao.cdk.sm.rest;

import com.hao.cdk.common.web.BaseRest;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hao.cdk.common.web.WebResponse;
import com.hao.cdk.common.pojo.IdDTO;
import com.hao.cdk.common.pojo.IdsDTO;
import com.hao.cdk.sm.domain.dto.accountuser.*;
import com.hao.cdk.sm.domain.vo.accountuser.*;
import com.hao.cdk.sm.service.IAccountUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @author: 许自豪
 * @date: 2025-01-23 14:20:42
 * @description: 用户(AccountUser)表控制层
 */
@Api(tags = "1.用户API")
@ApiSort(1)
@RestController
@RequestMapping("/accountUser")
public class AccountUserRest extends BaseRest {

    /**
     * Service服务对象
     */
    @Autowired
    private IAccountUserService accountUserService;

    /**
     * 分页查询
     *
     * @param dto 分页查询请求
     * @return 分页结果
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "1.分页查询")
    @PostMapping("/page")
    public WebResponse<IPage<AccountUserPageVO>> page(@ApiParam("分页查询请求")@Valid  @RequestBody AccountUserPageDTO dto) {
        return buildResponse(this.accountUserService.doPage(dto));
    }

    /**
     * 列表查询
     *
     * @param dto 列表查询请求
     * @return 列表结果
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "2.列表查询")
    @PostMapping("/list")
    public WebResponse<List<AccountUserListVO>> list(@ApiParam("列表查询请求") @RequestBody AccountUserListDTO dto) {
        return buildResponse(this.accountUserService.doList(dto));
    }

    /**
     * 获取单条数据
     *
     * @param dto 通过Id获取单条数据请求
     * @return 单条数据
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "3.获取单条数据")
    @PostMapping("/get")
    public WebResponse<AccountUserGetVO> get(@Valid @ApiParam("通过Id获取单条数据请求") @RequestBody IdDTO dto) {
        return buildResponse(this.accountUserService.doGetById(dto.getId()));
    }

    /**
     * 新增数据
     *
     * @param dto 新增实体请求
     * @return 新增结果
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "4.新增数据")
    @PostMapping("/save")
    public WebResponse<String> save(@Valid @ApiParam("新增实体请求") @RequestBody AccountUserSaveDTO dto) {
        return buildResponse(this.accountUserService.doSave(dto));
    }

    /**
     * 修改数据
     *
     * @param dto 修改实体请求
     * @return 修改结果
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "5.修改数据")
    @PostMapping("/update")
    public WebResponse<Boolean> update(@Valid @ApiParam("修改实体请求") @RequestBody AccountUserUpdateDTO dto) {
        return buildResponse(this.accountUserService.doUpdate(dto));
    }

    /**
     * 删除数据
     *
     * @param dto 根据id数组删除数据请求
     * @return 删除结果
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "6.删除数据")
    @PostMapping("/delete")
    public WebResponse<Boolean> delete(@Valid @ApiParam("根据id数组删除数据请求") @RequestBody IdsDTO dto) {
        return buildResponse(this.accountUserService.doDelete(dto.getIds()));
    }
    
    /**
     * 导入Excel
     *
     * @param file 文件
     * @return 导入结果
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "7.导入Excel")
    @PostMapping("/importExcel")
    public WebResponse<Boolean> importExcel(@ApiParam("导入文件") @RequestBody MultipartFile file) throws Exception {
        return buildResponse(this.accountUserService.importExcel(file, 1, 1));
    }

    /**
     * 导出excel（根据条件查询）
     *
     * @param dto 导入请求
     * @param response 响应结果
     */
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "8.导出excel")
    @PostMapping("/exportExcel")
    public void exportExcel(@ApiParam("导出主键集合") @RequestBody IdsDTO dto, HttpServletResponse response) {
        this.accountUserService.exportExcel(dto.getIds(), response);
    }
}
